package com.weixstudio.designmode.facade.demo_1;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @ClassName FileReader
 * @Description 读取文件示例
 * @Author liangw
 * @Date 2022/4/23 16:34
 * @Version 1.0
 **/
public class FileReader {

    public String read(String  fileNameSrc){
        System.out.println("读取文件，获取明文:");
        StringBuffer sb = new StringBuffer();

        try {
            FileInputStream inFs = new  FileInputStream(fileNameSrc);
            int data;
            while ((data=inFs.read())!=-1){
               sb = sb.append((char)data);
            }
            inFs.close();
            System.out.println(sb.toString());
        } catch (FileNotFoundException e) {
            System.out.println("文件不存在！");
        } catch (IOException e) {
            System.out.println("文件操作错误!");
        }
        return  sb.toString();
    }
}
